layui.define([ 'form', 'laydate', 'table' ,'util'], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var util = layui.util;
    var table = layui.table;
    var telentCardTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),telentCardTable)
            }
        },
        initTable:function(){
            telentCardTable = table.render({
                elem : '#telentCardTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/telentCard/list.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                //{type : 'checkbox', fixed:'left', },
                {
                    field : 'name',
                    title : '姓名',
                    align: 'center',
                    width:"120"
                }, {
                    field: 'cardNumber',
                    title: '证件号',
                    align: 'center',
                    width: "180"
                },
                {
                    field: 'gender',
                    title: '性别',
                    align: 'center',
                    width: "80",
                    templet:function(d){
                        if (d.gender == '1') {
                            return "男";
                        }else if (d.gender == '2') {
                            return "女";
                        }
                    }
                },
                {
                    field : 'level',
                    title : '等级',
                    align: 'center',
                    width: "100"
                },
                {
                    field : 'score',
                    title : '积分',
                    align: 'center',
                    width: "100"
                },
               /* {
                    field : 'userid',
                    title : ' 用户id，关联用户',
                    align: 'center',
                    width:"135"
                },*/
                {
                    field : 'startdate',
                    title : '起始有效日期',
                    align: 'center',
                    width: "160",
                    templet:function(d){return util.toDateString(d.startdate,"yyyy-MM-dd");}
                },
                {
                    field : 'enddate',
                    title : ' 截止日期',
                    align: 'center',
                    width: "160",
                    templet:function(d){return util.toDateString(d.enddate,"yyyy-MM-dd");}
                },
                {
                    field : 'seq',
                    title : '人才卡号',
                    align: 'center',
                    width: "180"
                }
        ]],
        done: function (res, curr, count) {
            $("[data-field='gender']").children().each(function () {

            });
        }

        });

            table.on('checkbox(telentCardTable)', function(obj){
                var telentCard = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),telentCardTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/telentCard/add.do";
                    Common.openDlg(url,"TelentCard>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"telentCardTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/telentCard/edit.do?id="+data.id;
                    Common.openDlg(url,"TelentCard>编辑");
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delBatch();
                    });
                }
            ,
                exportDocument : function() {
                    layui.use([ 'telentCardApi' ], function() {
                        var telentCardApi = layui.telentCardApi
                        Common.openConfirm("确认要导出这些TelentCard数据?", function() {
                            telentCardApi.exportExcel($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                importDocument:function(){
                    var uploadUrl = Common.ctxPath+"/cms/telentCard/excel/import.do";
                    //模板,
                    var templatePath= "/cms/telentCard/telentCard_upload_template.xls";
                    //公共的简单上传文件处理
                    var url = "/core/file/simpleUpload.do?uploadUrl="+uploadUrl+"&templatePath="+templatePath;
                    Common.openDlg(url, "TelentCard>上传");
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index',view);

});